//
//  NeedDealtCell.swift
//  newShaohuoRen
//
//  Created by hujinbiao on 2018/3/23.
//  Copyright © 2018年 hujinbiao. All rights reserved.
//

import UIKit

class NeedDealtCell: UITableViewCell {
    @IBOutlet weak var bgView: UIView!
    @IBOutlet weak var orderLabel: UILabel!
    @IBOutlet weak var itemNameLabel: UILabel!
    @IBOutlet weak var appointmentLabel: UILabel!
    @IBOutlet weak var sendAddressLabel: UILabel!
    @IBOutlet weak var nameLabel: UILabel!
    @IBOutlet weak var mobileLabel: UILabel!
    @IBOutlet weak var placeTimeLabel: UILabel!
    
    @IBOutlet weak var confirmButton: UIButton!
    @IBOutlet weak var cancelButton: UIButton!
    
    @IBOutlet weak var orderTypeImgView: UIImageView!
    //语音按钮
    @IBOutlet weak var recoderButton: UIButton!
    @IBOutlet weak var recoderButtonWidth: NSLayoutConstraint!
    
    var orderTypeArray = ["icon_myorder_bangmai","icon_myorder_bangsong","icon_myorder_luntai","icon_myorder_homeservice","icon_myorder_paidui","icon_myorder_liyi","icon_myorder_driver"]
    
    var recoder_manager = RecordManager()
    
    var _needItem : NeedDataItem?
    
    var needItem : NeedDataItem? {
        get {
            return _needItem
        }
        set {
            _needItem = newValue
            orderLabel.text = "订单号：\(_needItem!.order_num)"
            
            if _needItem?.video_time=="-1"{//文字
                recoderButton.isHidden = true
                itemNameLabel.isHidden = false
                itemNameLabel.text = "商品：\(_needItem!.item_name)"
            }else {//语音
                itemNameLabel.isHidden = true
                recoderButton.isHidden = false
                recoderButton.setTitle("\(_needItem!.video_time)''", for: .normal)
                recoderButtonWidth.constant = CGFloat(Int(_needItem!.video_time)!*10+40)
            }
            
            appointmentLabel.text = "预约时间：\(_needItem!.book_time_str)"
            if !((_needItem?.end_addr.isEmpty)!) {
                sendAddressLabel.text = "派件地址：\(_needItem!.end_addr)"
            }else if !((_needItem?.serve_addr.isEmpty)!) {
                sendAddressLabel.text = "派件地址：\(_needItem!.serve_addr)"
            }
            nameLabel.text = "联系人姓名：\(_needItem!.name)"
            mobileLabel.text = "联系人电话：\(_needItem!.mobile)"
            placeTimeLabel.text = "下单时间：\(_needItem!.create_time)"
            orderTypeImgView.image = UIImage(named: orderTypeArray[(Int((_needItem?.fc_id)!)!-1)])
            
            if _needItem?.fc_id == "2" {
                if _needItem?.status == "3"{
                    confirmButton.setTitle("确认取件", for: UIControlState())
                }else {
                    confirmButton.setTitle("确认送达", for: UIControlState())
                }
            }else {
                confirmButton.setTitle("确认送达", for: UIControlState())
            }
        }
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        
        bgView.layer.borderWidth = 1.0
        bgView.layer.borderColor = UIColor.lightGray.cgColor
        cancelButton.layer.borderWidth = 1
        cancelButton.layer.borderColor = UIColor(hexString: "#F5A623").cgColor
    }
    
    //播放语音
    @IBAction func recoderBtnAction(_ sender: UIButton) {
        recoder_manager.playRecoder(filePath: "\(endpoint)\(_needItem!.item_name)")
    }
}
